/* crypto.h - C headers for crypto.c 
 */

#include "idea.h" /* Declaration of IdeaCfbContext */

/* Used to determine if nesting should be allowed */
boolean legal_ctb(byte ctb);

/* Reads the first count bytes from infile into header */
int get_header_info_from_mfile(MemFile *infile, byte * header, int count);

#define ENCRYPT_IT FALSE		/* to pass to idea_file */
#define DECRYPT_IT TRUE 		/* to pass to idea_file */

int idea_file(byte *ideakey, boolean decryp, MemFile *f, MemFile *g, word32 lenfile);

/* Decrypt a file (RSA or IPES/IDEA) */
int decryptfile(char *infile, char *outfile, byte ideakey[16]);

/* Decompress a file with ZIP algorithm */
int decompress_file(MemFile *infile, MemFile *outfile);

#ifdef _VMS_VAXC
void write_mpi();
int read_mpi();
#else

/* Write a multiprecision integer to a file */
void write_mpi(unitptr n, MemFile * f, struct IdeaCfbContext *cfb);

/* Read a multiprecision integer from a file */
int read_mpi(unitptr r, MemFile * f, boolean adjust_precision,
 	     struct IdeaCfbContext *cfb);
#endif

/* Convert C <-> Quiche strings */
void CToPascal(char *s);
void PascalToC(char *s);

/*      Return date string, given pointer to 32-bit timestamp */
char *cdate(word32 * tstamp);

/*      Return date and time string, given pointer to 32-bit timestamp */
char *ctdate(word32 * tstamp);

/* Return current timestamp as a byte array and as a 32-bit word */
word32 get_timestamp(byte * timestamp);

/*      Returns the length of a packet according to the CTB and the
	length field */
word32 getpastlength(byte ctb, MemFile *f);

/* Write a CTB with the appropriate length field */
void write_ctb_len(MemFile * f, byte ctb_type, word32 length, boolean big);

/* Print an error message and return nonzero if val != checkval */
int version_error(int val, int checkval);
/* The same, if val is not a recognized version */
int version_byte_error(int val);

int make_signature_certificate(byte *certificate, struct MD5Context *MD,
   byte class, long keySerial, unitptr e, unitptr d, unitptr p, unitptr q, unitptr u, unitptr n);

#define RAND_PREFIX_LENGTH 8	/* Length of IV for IDEA encryption */

void InitMD5(MemFile *f);
int make_random_ideakey(byte key[IDEAKEYSIZE+RAND_PREFIX_LENGTH], int skip);
int squish_and_idea_file(byte *ideakey, MemFile *f, MemFile *g, boolean attempt_compression);
